Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: use specialization for more methods of impl Iterator for &mut I #138862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joboet
Copy link
Member

@joboet joboet commented Mar 23, 2025

...and get rid of ByRefSized. Most of the iterator methods can be forwarded to the inner iterator if we know that it is Sized, but this is currently only done for fold and try_fold. This PR adds the optimization for all applicable methods. It uses two private helper struct to hide the specialization from the public API:

  • Iterator for ByRefDefault only forwards the methods that can be used even when the iterator is not Sized, all other methods are left to the default.
  • Iterator for ByRef specializes on Sized and forwards to either the underlying iterator or to ByRefDefault

This PR also removes ByRefSized, the Iterator for &mut I should now be good enough to be used everywhere.

@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 23, 2025
@joboet joboet force-pushed the spec_iterator_by_ref branch from a23180d to c73f31f Compare March 23, 2025 19:27
@rust-log-analyzer

This comment has been minimized.

...and get rid of `ByRefSized`. Most of the iterator methods can be forwarded to the inner iterator if we know that it is `Sized`, but this is currently only done for `fold` and `try_fold`. This PR adds the optimization for all applicable methods. It uses two private helper struct to hide the specialization from the public API:
* `Iterator for ByRefDefault` only forwards the methods that can be used even when the iterator is not `Sized`, all other methods are left to the default.
* `Iterator for ByRef` specializes on `Sized` and forwards to either the underlying iterator or to `ByRefDefault`

This PR also removes `ByRefSized`, the `Iterator for &mut I` should now be good enough to be used everywhere.
@joboet joboet force-pushed the spec_iterator_by_ref branch from c73f31f to 3815e24 Compare March 23, 2025 21:03
@Noratrieb
Copy link
Member

r? The8472

@rustbot rustbot assigned the8472 and unassigned Noratrieb Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants